package org.seven.jrdp.scheduler.quartz;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.seven.jrdp.commons.util.ServletUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@DisallowConcurrentExecution
public class SessionJob implements Job {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		long startTime = System.currentTimeMillis();
		try {
			logger.info("会话调度启动...");
			DefaultWebSessionManager defaultWebSessionManager = ServletUtils.getBean(DefaultWebSessionManager.class);
			defaultWebSessionManager.validateSessions();
		} catch (Exception e) {
			logger.error("会话调度异常", e);
		} finally {
			logger.info("会话调度结束=>" + (System.currentTimeMillis() - startTime) / 1000 + "秒");
		}
	}
}